package com.bangyu.monitor.modular.system.warpper;

import cn.stylefeng.roses.core.base.warpper.BaseControllerWrapper;
import com.bangyu.monitor.core.common.constant.ConstantEnum;
import com.bangyu.monitor.core.util.Beans;
import com.bangyu.monitor.modular.system.entity.Risk;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.time.DateFormatUtils;

import java.util.List;
import java.util.Map;

/**
 * @Auther: zhangxue
 * @Date: 19/4/1 14:06
 * @Description:
 */
public class RiskWrapper extends BaseControllerWrapper {

    public RiskWrapper(Page page) {
        super(page.setRecords(Beans.beansToMaps(page.getRecords())));
    }

    public RiskWrapper(List<Risk> list) {
        super(Beans.beansToMaps(list));
    }

    @Override protected void wrapTheMap(Map<String, Object> map) {
        Object riskLevel = map.get("riskLevel");
        Object payloadTime = map.get("payloadTime");
        Object riskTime = map.get("riskTime");
        if (riskLevel != null) {
            map.put("payloadTime",DateFormatUtils.format(Long.parseLong(payloadTime.toString()),"yyyy-MM-dd hh:mm:ss:SSS"));
            map.put("riskTime",DateFormatUtils.format(Long.parseLong(riskTime.toString()),"yyyy-MM-dd hh:mm:ss:SSS"));
            map.put("riskLevelStr", ConstantEnum.RiskLevel.getValByKey(Integer.parseInt(riskLevel.toString())));
        }

    }
}
